import 'package:flutter/material.dart';
import 'screen_adapt/screen_adapt.dart';

main() => runApp(DBJApp());

class DBJApp extends StatelessWidget {
  const DBJApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text('屏幕适配'),
        ),
        body: DBJHomeBody(),
      ),
    );
  }
}

class DBJHomeBody extends StatefulWidget {
  const DBJHomeBody({Key? key}) : super(key: key);

  @override
  _DBJHomeBodyState createState() => _DBJHomeBodyState();
}

class _DBJHomeBodyState extends State<DBJHomeBody> {
  @override
  void initState() {
    super.initState();
    // 设备信息初始化
    YYYDeviceInfo.initialize();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _buildTitleWidget('屏幕宽度：${YYYDeviceInfo().screenWidth}'),
        _buildTitleWidget('屏幕高度：${YYYDeviceInfo().screenHeight}'),
        _buildTitleWidget('状态栏高度：${YYYDeviceInfo().statusBarHeight}'),
        _buildTitleWidget('底部栏高度：${YYYDeviceInfo().bottomBarHeight}'),
        _buildTitleWidget('文本缩放比例：${YYYDeviceInfo().textScaleFactor}'),
        _buildTitleWidget('设备分辨率：${YYYDeviceInfo().devicePixelRatio}'),
      ],
    );
  }

  Widget _buildTitleWidget(String title) {
    return Container(
      padding: EdgeInsets.only(left: 10.w),
      margin: EdgeInsets.only(bottom: 10.w),
      width: 290.w,
      height: 40.w,
      color: Colors.red,
      alignment: Alignment.centerLeft,
      child: Text(
        title,
        style: TextStyle(fontSize: 18.sp, color: Colors.white),
      ),
    );
  }
}
